package cn.stylefeng.guns.modular.system.service;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.modular.system.entity.Student;
import cn.stylefeng.guns.modular.system.mapper.StudentMapper;
import cn.stylefeng.guns.modular.system.model.StudentDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

@Service
public class StudentService extends ServiceImpl<StudentMapper, Student> {
    @Resource
    private StudentMapper stuMapper;

    /**
     * 查询所有学生信息
     * @return
     */
    public Page<Map<String, Object>> findStudent(){
        //通过layui获得分页信息
        Page page = LayuiPageFactory.defaultPage();
        return this.stuMapper.findStudent(page);
    }


    //删除
    public int delStudent(long stuid){
        return stuMapper.deleteById(stuid);
    }

    //按id查询
    public Student selectById(long stuid){
        return stuMapper.selectById(stuid);
    }

    //按id修改
    public int updateStudentById(Student student){
        return stuMapper.updateById(student);
    }

    public boolean addStudent(StudentDto stuDto){
        Student stu = new Student();
        BeanUtil.copyProperties(stuDto, stu);
        System.out.println(stu.getStuname()+".....................");
        return this.save(stu);
    }
}
